Access Service
Access service is a one of the main service of this project. This service is responsible for receiving requests from the above services such as webphone service, mobile service, ... and calling the below services such as user service, customer service, .. to perform the request, then return the results for the above services
I. Functionality
- Create, store, and manipulate data in
access-servicedatabase - Receive and direct requests to backend services
- Clean activity, create schedule reminder
- Authorize via a username and a password, exemplifying Basic Access Authentication
II. Packages
1. Dependencies
- Express - Node.js web application framework: Express
- Axios - Promise based HTTP client: Axios
- Winston - is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs. Each instance of a winston logger can have multiple transports configured at different levels: Winston
- ESLint - is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. In many ways, it is similar to JSLint and JSHint with a few exceptions: ESLint
- ESLint uses Espree for JavaScript parsing.
- ESLint uses an AST to evaluate patterns in code.
- ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
- Morgan - HTTP request logger middleware for node.js: Morgan
- co - Generator based control flow goodness for nodejs and the browser, using promises, letting you write non-blocking code in a nice-ish way: Co
- Shortid - creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Redis ids, and any other id users might see: Shortid
- By default 7-14 url-friendly characters: A-Z, a-z, 0-9, _-
- Non-sequential so they are not predictable.
- Supports cluster (automatically), custom seeds, custom alphabet.
- Can generate any number of ids without duplicates, even millions per day.
- Perfect for games, especially if you are concerned about cheating so you don't want an easily guessable id.
- Apps can be restarted any number of times without any chance of repeating an id.
- Popular replacement for Mongo ID/Mongoose ID.
- Works in Node, io.js, and web browsers.
- Includes Mocha tests.
- Nodemailer - is a module for Node.js applications to allow easy as cake email sending. Features: NodeMailer
- A single module with zero dependencies – code is easily auditable, as there are no dark corners
- Heavy focus on security, no-one likes RCE vulnerabilities
- Unicode support to use any characters, including emoji 💪
- Windows support – you can install it with npm on Windows just like any other module, there are no compiled dependencies. Use it hassle free from Azure or from your Windows box
- Use HTML content, as well as plain text alternative
- Add Attachments to messages
- Embedded image attachments for HTML content – your design does not get blocked
- Secure email delivery using TLS/STARTTLS
- Different transport methods in addition to the built-in SMTP support
- Sign messages with DKIM
- Custom Plugin support for manipulating messages
- Sane OAuth2 authentication
- Proxies for SMTP connections
- ES6 code – no more unintentional memory leaks, due to hoisted var’s
- MongoDB - The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users: https://github.com/mongodb/node-mongodb-native
- moment
- moment-timezone
2. Dev dependencies
- Babel-eslint - Babel-eslint allows you to lint ALL valid Babel code with the fantastic ESLint Babel Eslint
- Chai-as-promised - Extends Chai with assertions about promises. Chai-as-promised
- Chai - Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework. Chai
- Eslint - Eslint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. Eslint
- Mocha - Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha
- Nodemon - Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Nodemon
III. Database
1. ERD
2. Database schema
2.1. Callcenter
Callcenter is the main table to determine tenant. Each tenant is a callcenter.
| Field | Type | Description |
|---|---|---|
| _id | string | Unique identity string |
| name | string | name of callcenter |
| level | string | the current package that callcenter owner choose to use, each package has its limit (agents, functions) |
| createdAt | int64 | Timestamp of the document creation, in number of milliseconds since Unix epoch |
| updatedAt | int64 | Timestamp of the last update, in number of milliseconds since Unix epoch |
2.2. User
User stores user's credetials that user has signed up or invited. This determines which callcenter that user belong to.
| Field | Type | Description |
|---|---|---|
| _id | string | Unique identity string |
| fullName | string | display name of user |
| string | the email that user uses to authenticate | |
| password | string | password user uses to authenticate their access. This is a hashed string |
| salt | string | this is used to hash user's password by algorithm SHA512 |
| idCallcenter | string | _id of callcenter that user belongs to |
| createdAt | int64 | Timestamp of the document creation, in number of milliseconds since Unix epoch |
| updatedAt | int64 | Timestamp of the last update, in number of milliseconds since Unix epoch |
2.3. Confirm
Confirm is used to confirm user's signup, this will send a link to their email to make sure that email exists.
| Field | Type | Description |
|---|---|---|
| _id | string | Unique identity string |
| string | the email that user uses to sign up | |
| token | string | token to validate user's signup |
| expiredAt | int64 | Timestamp for the token will expire. After expire time, document will be deleted |
| createdAt | int64 | Timestamp of the document creation, in number of milliseconds since Unix epoch |
| updatedAt | int64 | Timestamp of the last update, in number of milliseconds since Unix epoch |
2.4. Invitation
Invitation is used to validate invited user, this will send a link to invited user's email to make sure that email exists.
| Field | Type | Description |
|---|---|---|
| _id | string | Unique identity string |
| string | invited user's email | |
| token | string | token to validate invited user |
| idCallcenter | string | _id of callcenter |
| idSip | string | _id of SIP account that admin has assigned |
| createdAt | int64 | Timestamp of the document creation, in number of milliseconds since Unix epoch |
| updatedAt | int64 | Timestamp of the last update, in number of milliseconds since Unix epoch |
2.5. ForgetPassword
ForgetPassword is used to help user has forgot password, this will send a link to their email to make sure that email exists in User table.
| Field | Type | Description |
|---|---|---|
| _id | string | Unique identity string |
| string | the email that user uses to sign up | |
| token | string | token to validate user's sign up |
| expiredAt | int64 | Timestamp for the token will expire. After expire time, document will be deleted |
| createdAt | int64 | Timestamp of the document creation, in number of milliseconds since Unix epoch |
| updatedAt | int64 | Timestamp of the last update, in number of milliseconds since Unix epoch |
IV. Source tree
.
├── .babelrc
├── config
│ ├── authorization.js
│ ├── host.js
│ ├── index.js
│ ├── keycloak.js
│ ├── mailer.js
│ ├── mongo.js
│ ├── redis.js
│ ├── services.js
│ └── version.js
├── Dockerfile
├── .dockerignore
├── entity
│ ├── Agent.js
│ ├── Callcenter.js
│ ├── ClickToCall.js
│ ├── Confirm.js
│ ├── Flowid.js
│ ├── Notification.js
│ ├── Reminder.js
│ └── User.js
├── .env
├── .eslintrc
├── .gitignore
├── groupAction.json
├── index.js
├── lib
│ ├── email.js
│ ├── feature.js
│ ├── integration
│ │ ├── freshsales.js
│ │ ├── hubspot.js
│ │ └── trigger.js
│ ├── keycloak.js
│ ├── logger.js
│ ├── password.js
│ ├── pubsub.js
│ ├── schedule.js
│ ├── script.js
│ ├── services.js
│ └── template
│ └── decentralization.js
├── middleware
│ └── authorization.js
├── model
│ ├── Callcenter.js
│ ├── ClickToCall.js
│ ├── Confirm.js
│ ├── Endpoint.js
│ ├── Flowid.js
│ ├── ForgetPassword.js
│ ├── Invite.js
│ ├── Key.js
│ ├── Notification.js
│ ├── Reminder.js
│ ├── SipAccountTracking.js
│ └── User.js
├── package.json
├── package-lock.json
├── role.json
├── role-old.json
├── route
│ ├── Activity.js
│ ├── Agent.js
│ ├── Callcenter.js
│ ├── Calllog.js
│ ├── ClickToCall.js
│ ├── Confirm.js
│ ├── ContactField.js
│ ├── ContactGroup.js
│ ├── Contact.js
│ ├── Domain.js
│ ├── Endpoint3rd.js
│ ├── EndpointApi.js
│ ├── ForgetPassword.js
│ ├── Fpt.js
│ ├── GroupField.js
│ ├── Hubspot.js
│ ├── Integrator.js
│ ├── Key.js
│ ├── MailService.js
│ ├── Mio.js
│ ├── Nexmo.js
│ ├── Nhanh.js
│ ├── Pbx.js
│ ├── Record.js
│ ├── Role.js
│ ├── Sapo.js
│ ├── SipAccount.js
│ ├── System.js
│ ├── Team.js
│ ├── Template3rd.js
│ ├── Template.js
│ ├── User.js
│ ├── v1
│ │ ├── Activity.js
│ │ ├── Agent.js
│ │ ├── Callcenter.js
│ │ ├── Calllog.js
│ │ ├── ClickToCall.js
│ │ ├── Confirm.js
│ │ ├── ContactField.js
│ │ ├── ContactGroup.js
│ │ ├── Contact.js
│ │ ├── Domain.js
│ │ ├── Endpoint3rd.js
│ │ ├── EndpointApi.js
│ │ ├── ForgetPassword.js
│ │ ├── Fpt.js
│ │ ├── GroupField.js
│ │ ├── Hubspot.js
│ │ ├── index.js
│ │ ├── Integrator.js
│ │ ├── Key.js
│ │ ├── MailService.js
│ │ ├── Mio.js
│ │ ├── Nexmo.js
│ │ ├── Nhanh.js
│ │ ├── Pbx.js
│ │ ├── Record.js
│ │ ├── Role.js
│ │ ├── Sapo.js
│ │ ├── SipAccount.js
│ │ ├── System.js
│ │ ├── Team.js
│ │ ├── Template3rd.js
│ │ ├── Template.js
│ │ ├── User.js
│ │ └── Vietguy.js
│ └── Vietguy.js
├── server.js
├── sources
│ ├── api.yaml
│ └── images
│ ├── ERD-access-service.png
│ ├── ERD.jpg
│ └── microservice-model.jpg
├── template
│ ├── custom-mail.en.html
│ ├── custom-mail.vi.html
│ ├── forget-callcenter-name.html
│ ├── forget-password.html
│ ├── reminder.html
│ ├── shopify-revoke-sip.html
│ ├── signup-confirm.en.html
│ ├── signup-confirm-shopify.html
│ ├── signup-confirm.vi.html
│ ├── signup-invite.html
│ ├── signup-success.html
│ ├── signup-success-without-trial-sip.html
│ └── signup-success-with-trial-sip.html
├── template.json
└── test
├── entity
│ ├── Agent.js
│ ├── Callcenter.js
│ ├── Confirm.js
│ └── User.js
├── lib
│ ├── email.js
│ └── password.js
└── model
├── Callcenter.js
├── Confirm.js
├── ForgetPassword.js
├── Invite.js
└── User.js
V. Installation
- Clone project:
git clone https://gitlab.com/gcalls-opensource/gcallsmiddle.git
- Change dir into access-service folder
cd access-service
- Install utility modules:
npm install
- Lint project
npm run lint
Start server:
run local
npm run localrun in development
npm install -g pm2
npm run devrun in production
npm install -g pm2
npm start
Test
Before test make sure you have mongo installed
Test all
npm testTest model
npm run test-model- Test entity
npm run test-entity- Test library
npm run test-lib
VI. API
Please visit API documentation for more details
VII Author
- Duong Cat Hung Vuong vuong.duong@gcalls.co💣 - Fullstack engineer at Gcalls Vietnam Pte Ltd